from PySide6.QtCore import QSize, QTimer
from PySide6.QtWidgets import QMessageBox, QPushButton

class MessageBoxFunc(object):
    def ShowMessageBox(title, content, parent, icon = QMessageBox.Icon.Information, timeoutS=3000):
        MyBox = QMessageBox(icon, title, content, QMessageBox.StandardButton.NoButton, parent)
        MyBox.setMinimumSize(QSize(400, 200))

        button = QPushButton("好的", MyBox)
        button.setMinimumSize(QSize(120, 40))
        MyBox.addButton(button, QMessageBox.AcceptRole)

        if timeoutS > 0 and timeoutS < 300 * 1000:
            timer = QTimer(MyBox)
            timer.setInterval(timeoutS)
            timer.timeout.connect(MyBox.close)  # 设置超时后自动关闭窗口
            timer.start()

        MyBox.exec()
